-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support server event streams #1479
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start! It's exciting to see this working 😄
...tware/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt
Outdated
Show resolved
Hide resolved
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/EventStreamSymbolProvider.kt
Outdated
Show resolved
Hide resolved
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/EventStreamSymbolProvider.kt
Outdated
Show resolved
Hide resolved
...src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/EventStreamDecorator.kt
Outdated
Show resolved
Hide resolved
...src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/EventStreamDecorator.kt
Outdated
Show resolved
Hide resolved
...in/software/amazon/smithy/rust/codegen/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt
Show resolved
Hide resolved
...in/software/amazon/smithy/rust/codegen/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt
Show resolved
Hide resolved
...otlin/software/amazon/smithy/rust/codegen/smithy/transformers/RemoveEventStreamOperations.kt
Outdated
Show resolved
Hide resolved
...src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/EventStreamDecorator.kt
Outdated
Show resolved
Hide resolved
aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt
Outdated
Show resolved
Hide resolved
aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4SigningDecorator.kt
Outdated
Show resolved
Hide resolved
...in/software/amazon/smithy/rust/codegen/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might have misunderstood event stream errors, and that's what most of my comments are about. Other than errors and the removal of the event stream allow list, I think this looks good. Both of these need to be addressed before approval though.
...er/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt
Outdated
Show resolved
Hide resolved
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RustSettings.kt
Outdated
Show resolved
Hide resolved
...tlin/software/amazon/smithy/rust/codegen/smithy/customize/NoOpEventStreamSigningDecorator.kt
Outdated
Show resolved
Hide resolved
...ftware/amazon/smithy/rust/codegen/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt
Outdated
Show resolved
Hide resolved
...otlin/software/amazon/smithy/rust/codegen/smithy/transformers/RemoveEventStreamOperations.kt
Outdated
Show resolved
Hide resolved
...main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/EventStreamNormalizer.kt
Outdated
Show resolved
Hide resolved
...kotlin/software/amazon/smithy/rust/codegen/smithy/generators/error/CombinedErrorGenerator.kt
Outdated
Show resolved
Hide resolved
...main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/EventStreamNormalizer.kt
Show resolved
Hide resolved
...software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGenerator.kt
Outdated
Show resolved
Hide resolved
...software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGenerator.kt
Outdated
Show resolved
Hide resolved
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/EventStreamSymbolProvider.kt
Outdated
Show resolved
Hide resolved
...lin/software/amazon/smithy/rust/codegen/smithy/generators/config/EventStreamSigningConfig.kt
Outdated
Show resolved
Hide resolved
...kotlin/software/amazon/smithy/rust/codegen/smithy/generators/error/CombinedErrorGenerator.kt
Outdated
Show resolved
Hide resolved
...kotlin/software/amazon/smithy/rust/codegen/smithy/generators/error/TopLevelErrorGenerator.kt
Outdated
Show resolved
Hide resolved
@@ -37,3 +80,40 @@ object EventStreamNormalizer { | |||
.build() | |||
} | |||
} | |||
|
|||
fun OperationShape.operationErrors(model: Model): List<Shape> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the intent for this function? The OperationIndex.getErrors
already returns all the errors for the operation, right? So why does it need to be filtered by the synthetic trait? Wouldn't all of them have it since the normalizer added it to all of them?
...main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/EventStreamNormalizer.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I have added some minor comments. This PR will break as soon as you merge in the Python server, so some other adjustments are needed.
One thing I suggest you to do is to throw a CodegenException if EventStreams are used in model built with the Python plugin.
...software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGenerator.kt
Outdated
Show resolved
Hide resolved
RestJsonHttpBindingResolver(codegenContext.model, ProtocolContentTypes.consistent("application/json")) | ||
RestJsonHttpBindingResolver(codegenContext.model, ProtocolContentTypes("application/json", "application/json", "application/vnd.amazon.eventstream")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does.
import software.amazon.smithy.rust.codegen.util.hasTrait | ||
import software.amazon.smithy.rust.codegen.util.toPascalCase | ||
|
||
class EventStreamErrorMarshallerGenerator( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add some documentation to this class and methods..
...ware/amazon/smithy/rust/codegen/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt
Outdated
Show resolved
Hide resolved
...ware/amazon/smithy/rust/codegen/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt
Outdated
Show resolved
Hide resolved
...ware/amazon/smithy/rust/codegen/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt
Outdated
Show resolved
Hide resolved
@@ -10,15 +10,42 @@ | |||
use std::time::Duration; | |||
|
|||
use crate::helpers::{client, PokemonService}; | |||
use async_stream::stream; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be aware the this file is currently symlinked inside the Python folder. You will need to copy the original implementation there since event streams are not supported yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to take a look at the codegen diff and CI results before approving, but I think overall this looks good! One question remaining that may or may not require changes.
} | ||
fun transform(model: Model): Model = ModelTransformer.create().mapShapes(model) { shape -> | ||
if (shape is OperationShape && shape.isEventStream(model)) { | ||
addStreamErrorsToOperationErrors(model, shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this affect the top-level error, the operation error, or both? I think the intention is to only have the top-level error hold both the operation and streaming errors in it.
* Server event streams * Rename EventStreamInput to EventStreamSender * Make event stream errors optional * Pokemon service model updated * Pokemon server event handler * Pokemon client to test event streams * EventStreamDecorator to make optional using SigV4 signing Closes: #1157 Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow! This is an incredible piece of engineering with a lot of cool ideas baked in. Really impressed with how quick this came together.
In the current state of the PR I can't really evaluate the changes, especially the changes around errors for event streams. Here's what I'd suggest:
- An RFC / design doc (doesn't need to be long) or an addition to the docs folder explaining different union shape structures and the event stream types we plan to generate
- As possible, split out the most complex pieces of code into standalone PRs with tests, eg. the changes to EventStream normalization can stand alone I think?
import software.amazon.smithy.rust.codegen.util.hasTrait | ||
import software.amazon.smithy.rust.codegen.util.toPascalCase | ||
|
||
class EventStreamErrorMarshallerGenerator( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this really need to inherit? can we refactor for composition?
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
A new generated diff is ready to view.
A new doc preview is ready to view. |
Signed-off-by: Daniele Ahmed <[email protected]>
A new generated diff is ready to view.
A new doc preview is ready to view. |
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
A new generated diff is ready to view.
A new doc preview is ready to view. |
Signed-off-by: Daniele Ahmed <[email protected]>
A new generated diff is ready to view.
A new doc preview is ready to view. |
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
A new generated diff is ready to view.
A new doc preview is ready to view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work! 🚀
I checked out the changes locally and verified that the Amazon Transcribe streaming example still works correctly. Also looked through the generated documentation to see how the errors look there. Everything looks good to me.
Overall, I'm happy with these changes. The only snag left is that the codegen diff doesn't show a diff for a full service thanks to #1219. I think if we get #1565 merged, and then update this with the latest main, the diff will be small enough that we can see a full service diffed. Seeing that would be a nice sanity check.
I think we're very close to getting this merged. @rcoh or @Velfi, feel free to approve on my behalf if I'm not available to review with the changelog and codegen diff updates in.
Signed-off-by: Daniele Ahmed <[email protected]>
A new generated diff is ready to view.
A new doc preview is ready to view. |
I tried #1565 here, but the diff of errors is still as large (20k lines). Instead, with and without #1565, I generated the whole SDK for both |
Signed-off-by: Daniele Ahmed <[email protected]>
A new generated diff is ready to view.
A new doc preview is ready to view. |
@@ -74,7 +74,7 @@ open class ServerServiceGenerator( | |||
|
|||
// Render combined errors. | |||
open fun renderCombinedErrors(writer: RustWriter, operation: OperationShape) { | |||
ServerCombinedErrorGenerator(coreCodegenContext.model, coreCodegenContext.symbolProvider, operation).render(writer) | |||
/* Subclasses can override */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make it abstract?
…degenVisitor` This is a holdover from when the server subproject was started. We've never utilized this model transformer, nor will we have any use for it now, since event stream operations are supported in the server since #1479. See #1762 (comment)
…degenVisitor` (#1764) This is a holdover from when the server subproject was started. We've never utilized this model transformer, nor will we have any use for it now, since event stream operations are supported in the server since #1479. See #1762 (comment).
Support server event streams
Closes: #1157
Motivation and Context
This PR adds support for server event streams. See #1157
Description
This PR adds support for server event streams and updates the Pokemon model and service to use them
Testing
./gradlew :codegen-server-test:test
./gradlew :codegen-test:test
Checklist
CHANGELOG.next.toml
if I made changes to the smithy-rs codegen or runtime cratesCHANGELOG.next.toml
if I made changes to the AWS SDK, generated SDK code, or SDK runtime cratesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.